package game.screen;

import java.util.ArrayList;

import game.logic.GameControl;
import game.particles.AbsParticle;
import game.particles.ParticleCloudFire;
import game.particles.Particle_1;
import game.shared.Constants;
import game.shared.Resources;
import game.windows.Button;
import game.windows.Form;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;

public class ScreenMenu extends AbsScreen {

	private Texture texture;
	private Texture tMenu;
	private int iSelect;
	private BitmapFont font;
    AbsParticle particle_1;
	AbsParticle particleSpringWater;
    Form menu;
	String s;
	private int count;
	public ScreenMenu(GameControl _gameControl) {
		super(_gameControl);
		id = Constants.SCREEN_MENU;
		texture = new Texture(Constants.MENU_BACKGROUND_TEXTURE);
		tMenu = new Texture(Constants.MENU_TEXTURE);
		iSelect = 0;
		font = new BitmapFont();
		s = new String();
		s = "null";
		count = 0;
//      sb.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        particle_1 = new Particle_1();
        particle_1.render(sb);
        particleSpringWater = new Particle_1("res/particles/particle_rain", "res/particles");
        particleSpringWater.setPosition(-100, Gdx.graphics.getHeight());
		Resources.LoadResource("res/resources.txt");
        menu = new Form();
        menu.setXY(50, 50);
        menu.setbDrawWatermark(false);
        CreateMenu();
	}
	
	private void CreateMenu() {
		Button bt = new Button(Constants.FUNCTION_CODE_NEWGAME, Resources.getTextureRegion(Resources.MENU_NEWGAME), Resources.getTextureRegion(Resources.MENU_NEWGAME_2));
		bt.setXY(0, 150);
		menu.addControl(bt);
		bt = new Button(Constants.FUNCTION_CODE_CONTINUE_GAME, Resources.getTextureRegion(Resources.MENU_CONTINUE_GAME), Resources.getTextureRegion(Resources.MENU_CONTINUE_GAME_2));
		bt.setXY(0, 120);
		menu.addControl(bt);
		bt = new Button(Constants.FUNCTION_CODE_OPTION, Resources.getTextureRegion(Resources.MENU_OPTION), Resources.getTextureRegion(Resources.MENU_OPTION_2));
		bt.setXY(0, 90);
		menu.addControl(bt);
		bt = new Button(Constants.FUNCTION_CODE_CREDIT, Resources.getTextureRegion(Resources.MENU_CREDIT), Resources.getTextureRegion(Resources.MENU_CREDIT_2));
		bt.setXY(0, 60);
		menu.addControl(bt);
		bt = new Button(Constants.FUNCTION_CODE_EXIT, Resources.getTextureRegion(Resources.MENU_EXIT), Resources.getTextureRegion(Resources.MENU_EXIT_2));
		bt.setXY(0, 30);
		menu.addControl(bt);
	}

	@Override
	public void update() {
		count ++;
		if(Gdx.input.isTouched()){
			particle_1.setPosition(Gdx.input.getX(), Constants.SCREEN_HEIGHT - Gdx.input.getY());
			particle_1.update();
		}
		menu.update();
		dispatch();
	}
	
	private void dispatch() {
		int f = Constants.get_RETURN_CODE();
		switch (f) 
		{
		case Constants.FUNCTION_CODE_NEWGAME:
			gameControl.setScreen(Constants.SCREEN_SELECT_LEVEL);
			break;
		case Constants.FUNCTION_CODE_CONTINUE_GAME:
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		case Constants.FUNCTION_CODE_OPTION:
			break;
		case Constants.FUNCTION_CODE_CREDIT:
			break;
		case Constants.FUNCTION_CODE_EXIT:
			gameControl.dispose();
			break;
		default:
			break;
		}
	}

	@Override
	public void render(float arg0) {
		
		if(sb!= null)
		{
			sb.begin();
			
			if(texture != null)
				sb.draw(texture, 0, (Constants.SCREEN_HEIGHT - texture.getHeight())/2);
		
			font.draw(sb, String.valueOf(Gdx.graphics.getDeltaTime()), Constants.SCREEN_WIDTH-100, Constants.SCREEN_HEIGHT-100);
			font.draw(sb, String.valueOf(Gdx.graphics.getFramesPerSecond()) + " frames/s.", Constants.SCREEN_WIDTH - 100, Constants.SCREEN_HEIGHT - 130);
			particle_1.render(sb);
			particleSpringWater.render(sb);
			menu.render(sb);
			
			sb.end();
		}		
	}	
}
